package com.lgr.store.service;

import com.lgr.store.dao.StorageReportDAO;
import com.lgr.store.utils.ContextUtils;
import com.lgr.store.utils.PageObject;
import com.lgr.store.vo.MaterialReportVo;
import com.lgr.store.vo.OrdersVo;
import com.lgr.store.vo.ProdTypeVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StorageReportService {
    @Resource
	StorageReportDAO reportDAO;
	@Transactional
	public List<OrdersVo> listDetail(OrdersVo ord, PageObject pager){
		if(pager!=null) {
			int count = reportDAO.count(ord);
			pager.setTotalRows(count);
		}
		return  reportDAO.listDetail(ord,pager);
	}
	@Transactional
	public List<MaterialReportVo> storageStat(OrdersVo ord,PageObject pager){
		Map<String, String> params = new HashMap<String, String>();
		params.put("materialName", ord.getRemark());
		params.put("storageId", ord.getSupplierId()+"");
		params.put("startDate", ord.getOrderDate());
		params.put("endDate", ord.getOrderDate2());
		//执行存储过程
		reportDAO.storageStat(params);
		List<MaterialReportVo> reportList = null;
		if(pager !=null){
			int cnt = reportDAO.statCount();
			pager.setTotalRows(cnt);
		}
		reportList = reportDAO.statList(pager);
		return  reportList;
	}
}